const db = wx.cloud.database()
const questionList = db.collection('user')
let all = []
let userIntegrals
Page({
  /**
   * 页面的初始数据
   */
  data: {
    subject: [],
  },


  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {

    let all = []
    //1.获取数据的个数
    let count = await db.collection('user').count()
    count = count.total
    //2.通过for循环做多次请求，并把多次请求的数据放在一个数组里

    for (let i = 0; i < count; i += 20) { //自己设置每次获取数据的量
      let list = await db.collection('user').orderBy('userIntegral', 'desc').skip(i).get()
      all = all.concat(list.data)
    }
    let subject = all
    this.setData({
      subject: subject
    })

  },
  // 点赞

  like: function (e) {
    let subject = this.data.subject
  // console.log(subject[e.currentTarget.dataset.index]._openid)
  db.collection('user').doc(subject[e.currentTarget.dataset.index]._openid).get()
  .then(res=>{
    var like = res.data.like+=3
    db.collection('user').doc(subject[e.currentTarget.dataset.index]._openid).update({
      data:{
        like:like
      }
     
    })

    this.onLoad()
})

},
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

    wx.stopPullDownRefresh();
    this.onLoad()

  }
})